#include<iostream>
using namespace std;
const int N = 200 * 200 + 10;
int f[N];
int n, m;
int get(int x, int y)
{
	return x * n + y;
}
int find(int x)
{
	if (x != f[x]) {
		f[x] = find(f[x]);
	}
	return f[x];
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n * n; i++) {
		f[i] = i;
	}
	int res = 0;
	for (int i = 1; i <= m; i++) {
		int x, y;
		char d;
		cin >> x >> y >> d;
		x--;
		y--;
		int a = get(x, y);
		int b = 0;
		if (d == 'D') {
			b = get(x + 1, y);	
		}
		else {
			b = get(x, y + 1);
		}
		int pa = find(a);
		int pb = find(b);
		if (pa == pb) {
			res = i;
			break;
		}
		else {
			f[pa] = pb;
		}
	}
	if (!res) {
		cout << "draw" << endl;
	}
	else {
		cout << res << endl;
	}
	return 0;
}